package com.awspaas.user.apps.cpq.controller;

import java.util.HashMap;
import java.util.Map;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.BOCopyAPI;
import com.actionsoft.sdk.local.api.BOQueryAPI;

public class CPQ_GetInstallationFeeWeb {

	public String getInstallationFee(UserContext userContext, String bindId) {
	     try {
	    	BO data= SDK.getBOAPI().query("BO_EU_CPQ_TEMPLATE_PRICE").bindId(bindId).detail();
	    	BOQueryAPI bos=SDK.getBOAPI().query("BO_EU_CPQ_TEMPLATE_PARAMETER").bindId(bindId);
	    	BO oldBo=SDK.getBOAPI().query("BO_EU_CQP_INSTALLATION_FEE_TEMPLATE").addQuery("GLXMID=", bindId).detail();
	    	if(null!=oldBo) {
	    		SDK.getBOAPI().removeByBindId("BO_EU_CQP_INSTALLATION_FEE_TEMPLATE",oldBo.getBindId());
	    		SDK.getBOAPI().removeByBindId("BO_EU_CQP_INSTALLATION_FEE_TEMPLATE_P",oldBo.getBindId());
	    		SDK.getBOAPI().removeByBindId("BO_EU_CQP_INSTALLATION_FEE_TEMPLATE_GRID",oldBo.getBindId());
	    	}
	    	String XMLX=data.getString("XMLX");//项目类型
	    	String CPXH=data.getString("CPXH");//产品型号
	    	String APPLYNO=data.getString("APPLYNO");//表单编号
            BO bo=new BO();
            bo.set("XMLX",XMLX );
            bo.set("CPXH", CPXH);
            bo.set("GLXMID", bindId);
            String pid=  SDK.getProcessAPI().createBOProcessInstance("obj_8f31cff02b35409f8fe4d96fab1ef340", userContext.getUID(), "").getId();
	    	SDK.getBOAPI().create("BO_EU_CQP_INSTALLATION_FEE_TEMPLATE", bo, pid, userContext.getUID());
	    	BOCopyAPI copyBo=bos.copyTo("BO_EU_CQP_INSTALLATION_FEE_TEMPLATE_P", pid);
	    	copyBo.exec();
	    	ResponseObject ro = ResponseObject.newOkResponse();
			Map<String, String> map=new HashMap<String, String>();
			map.put("bindId", pid);
			ro.setData(map);
			return ro.toString();	
		} catch (Exception e) {
			throw  e;
		}
	
	}

}
